{
  "cells": [
    {
      "cell_type": "markdown",
      "id": 3.0293430767166755e+38,
      "metadata": {
        "id": 3.0293430767166755e+38
      },
      "source": [
        "# Gradio Demo: unified_demo_text_generation"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": 2.7299665331067346e+38,
      "metadata": {
        "id": 2.7299665331067346e+38
      },
      "outputs": [],
      "source": [
        "!pip install -q gradio\n",
        "!pip install transformers"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import gradio as gr\n",
        "from transformers import pipeline\n",
        "\n",
        "generator = pipeline('text-generation', model = 'gpt2')\n",
        "\n",
        "def generate_text(text_prompt):\n",
        "  response = generator(text_prompt, max_length = 30, num_return_sequences=5)\n",
        "  return response[0]['generated_text']\n",
        "\n",
        "textbox = gr.Textbox()\n",
        "\n",
        "demo = gr.Interface(generate_text, textbox, textbox)\n",
        "\n",
        "if __name__ == \"__main__\":\n",
        "    demo.launch()"
      ],
      "metadata": {
        "id": "iXtWWtxE6_sr"
      },
      "id": "iXtWWtxE6_sr",
      "execution_count": null,
      "outputs": []
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}